# -*- coding: utf-8 -*-
# @Time: 2021/11/27 13:51
# @Author: lijinxi
# @File    : computation_ratio.py
# @desc

import matplotlib as mpl
from matplotlib.ticker import MultipleLocator
from scipy.interpolate import make_interp_spline
import numpy as np
from scipy import interpolate
# 画图的模块
import matplotlib.pyplot as plt

mpl.rcParams["axes.unicode_minus"] = False
X1 = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]
Y1 = [-0.0, 15.0, 36.0, 56.0, 68.0, 81.0, 94.0, 107.0, 117.0, 131.0, 140.0, 149.0, 157.0, 164.0, 174.0, 184.0, 192.0,
      196.0, 196.0, 199.0, 200]
Y2 = [0, 19, 33, 45, 60, 71, 82, 93, 102, 110, 117, 124, 130, 137, 142, 150, 153, 158, 162, 167, 167]

X1, Y1 = np.array(X1), np.array(Y1) / 200

func = interpolate.interp1d(X1, Y1, kind='cubic')
x_new = np.linspace(0, 2, 40)
y_new = make_interp_spline(X1, Y1)(x_new)
plt.plot(X1, Y1, 'g-', linewidth=2, label="NBS")

X2, Y2 = np.array(X1), np.array(Y2) / 200

func = interpolate.interp1d(X2, Y2, kind='cubic')
x_new = np.linspace(0, 2, 40)
y_new = func(x_new)
plt.plot(X1, Y2, 'r-', linewidth=2, label="KSP(K=3)")
# plt.title('Squares',fontsize=24)
plt.tick_params(axis='both', which='major', labelsize=18)
plt.xlabel('Total Computing Capacity', fontsize=18)
plt.ylabel('Acceptance Ratio', fontsize=18)
x_major_locator = MultipleLocator(0.4)
y_major_locator = MultipleLocator(0.20)
ax = plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(-0.1, 2)
plt.ylim(0, 1)
plt.plot([1.3, 1.3], [0, 0.81], ls='--', c='grey')
plt.plot([1.8, 1.8], [0., 0.81], ls='--', c='grey')
plt.plot([-0.1, 1.8], [0.81, 0.81], ls='--', c='grey')
plt.yticks([0.0, 0.20, 0.40, 0.60, 0.80, 1.00])
plt.xticks([0.0, 0.40, 1.0, 1.3, 1.8, ])
plt.legend(fontsize=18, frameon=False,ncol=2,loc=2)
plt.axhline(y=0.2, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=0.4, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=0.6, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=0.8, color='lightgray', ls=':', linewidth=1)
plt.savefig('computation_ratio.pdf', bbox_inches='tight')
plt.show()
